#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QDialog* dialog = new QDialog(this);
    // 设置对话框大小
    dialog->resize(400,300);

    // 设置对话框标题
    dialog->setWindowTitle("对话框");

    // 添加控件
    QLabel* label = new QLabel("这是一个对话框",dialog);
    QPushButton* button = new QPushButton("点击关闭",dialog);
    QVBoxLayout* layout = new QVBoxLayout();
    layout->addWidget(label);
    layout->addWidget(button);
    dialog->setLayout(layout);

    // 设置在关闭是自动 delete
    dialog->setAttribute(Qt::WA_DeleteOnClose);
    // 关联槽函数
    connect(button,&QPushButton::clicked,dialog,&QDialog::close);

    //显示对话框
    dialog->show();

//    dialog->
}
